package com.xxx.control.net

import androidx.lifecycle.LifecycleOwner
import com.uber.autodispose.*
import io.reactivex.*

/**
 * 
 * date: 2020/07/02
 * desc:
 */


/*
* 对Single添加拓展函数
*/
fun <T> Single<T>.transform(owner: LifecycleOwner): SingleSubscribeProxy<T> {
    return this.compose(RxScheduler.singleOnMainThread())
            .`as`(RxScheduler.bindLifecycle(owner))
}

fun <T> Single<T>.singleOnMainThread(): Single<T> {
    return this.compose(RxScheduler.singleOnMainThread())
}

/**
 * 对Observable的拓展函数
 */
fun <T> Observable<T>.transform(owner: LifecycleOwner): ObservableSubscribeProxy<T> {
    return this.compose(RxScheduler.observeOnMainThread())
            .`as`(RxScheduler.bindLifecycle(owner))
}

fun <T> Observable<T>.observeOnMainThread(): Observable<T> {
    return this.compose(RxScheduler.observeOnMainThread())
}


fun <T> Flowable<T>.transform(owner: LifecycleOwner): FlowableSubscribeProxy<T> {
    return this.compose(RxScheduler.flowableOnMainThread())
            .`as`(RxScheduler.bindLifecycle(owner))
}
fun <T> Flowable<T>.flowableOnMainThread(): Flowable<T> {
    return this.compose(RxScheduler.flowableOnMainThread())
}




